﻿using System;
using System.IO;
using Manager;
using UnityEngine;

namespace Studio
{
	// Token: 0x02000533 RID: 1331
	public class OutsideSoundCtrl
	{
		// Token: 0x17000415 RID: 1045
		// (get) Token: 0x060021FE RID: 8702 RVA: 0x000CE414 File Offset: 0x000CC614
		// (set) Token: 0x060021FF RID: 8703 RVA: 0x000CE41C File Offset: 0x000CC61C
		public BGMCtrl.Repeat repeat
		{
			get
			{
				return this.m_Repeat;
			}
			set
			{
				if (Utility.SetStruct<BGMCtrl.Repeat>(ref this.m_Repeat, value) && this.audioSource)
				{
					this.audioSource.loop = (this.repeat == BGMCtrl.Repeat.All);
				}
			}
		}

		// Token: 0x17000416 RID: 1046
		// (get) Token: 0x06002200 RID: 8704 RVA: 0x000CE454 File Offset: 0x000CC654
		// (set) Token: 0x06002201 RID: 8705 RVA: 0x000CE45C File Offset: 0x000CC65C
		public string fileName
		{
			get
			{
				return this.m_FileName;
			}
			set
			{
				if (this.m_FileName != value)
				{
					this.Play(value);
				}
			}
		}

		// Token: 0x17000417 RID: 1047
		// (get) Token: 0x06002202 RID: 8706 RVA: 0x000CE478 File Offset: 0x000CC678
		// (set) Token: 0x06002203 RID: 8707 RVA: 0x000CE480 File Offset: 0x000CC680
		public bool play
		{
			get
			{
				return this.m_Play;
			}
			set
			{
				if (Utility.SetStruct<bool>(ref this.m_Play, value))
				{
					if (this.m_Play)
					{
						this.Play();
					}
					else
					{
						this.Stop();
					}
				}
			}
		}

		// Token: 0x06002204 RID: 8708 RVA: 0x000CE4B0 File Offset: 0x000CC6B0
		public void Play()
		{
			this.m_Play = true;
			this.Play(this.m_FileName);
		}

		// Token: 0x06002205 RID: 8709 RVA: 0x000CE4C8 File Offset: 0x000CC6C8
		public void Play(string _file)
		{
			this.m_FileName = _file;
			if (!this.m_Play)
			{
				return;
			}
			string path = UserData.Create("audio") + _file;
			if (!File.Exists(path))
			{
				return;
			}
			if (Singleton<Studio>.Instance.bgmCtrl.play)
			{
				Singleton<Studio>.Instance.bgmCtrl.Stop();
			}
			Singleton<Manager.Sound>.Instance.StopBGM(0f);
			AudioClip audioClip = ExternalAudioClip.Load(path);
			if (audioClip == null)
			{
				GlobalData.Debug_LogWarning(string.Format("看不懂 : {0}", _file));
				return;
			}
			this.audioSource = Singleton<Manager.Sound>.Instance.Play(Manager.Sound.Type.BGM, audioClip, 0f);
		}

		// Token: 0x06002206 RID: 8710 RVA: 0x000CE574 File Offset: 0x000CC774
		public void Stop()
		{
			this.m_Play = false;
			Singleton<Manager.Sound>.Instance.Stop(Manager.Sound.Type.BGM);
		}

		// Token: 0x06002207 RID: 8711 RVA: 0x000CE588 File Offset: 0x000CC788
		public void Save(BinaryWriter _writer, Version _version)
		{
			_writer.Write((int)this.m_Repeat);
			_writer.Write(this.m_FileName);
			_writer.Write(this.m_Play);
		}

		// Token: 0x06002208 RID: 8712 RVA: 0x000CE5B0 File Offset: 0x000CC7B0
		public void Load(BinaryReader _reader, Version _version)
		{
			this.m_Repeat = (BGMCtrl.Repeat)_reader.ReadInt32();
			this.m_FileName = _reader.ReadString();
			this.m_Play = _reader.ReadBoolean();
		}

		// Token: 0x0400233C RID: 9020
		public const string dataPath = "audio";

		// Token: 0x0400233D RID: 9021
		private BGMCtrl.Repeat m_Repeat = BGMCtrl.Repeat.All;

		// Token: 0x0400233E RID: 9022
		private string m_FileName = string.Empty;

		// Token: 0x0400233F RID: 9023
		private bool m_Play;

		// Token: 0x04002340 RID: 9024
		private AudioSource audioSource;
	}
}
